﻿using System;
using System.Configuration;
using System.Collections.Generic;
using IGolovkine.ShoutCastRipper;
using IGolovkine.Core.Diagnostics;

namespace IGolovkine.ShoutCastRipper.Service.Configuration
{
    public class StationRipperElement : ConfigurationElement
    {
        private const string NameTag = "name";
        private const string UrlTag = "url";
        private const string UserAgentTag = "userAgent";
        private const string ArchiveFolderTag = "archiveFolder";
        
        private const string MaximumProbingPeriodTag = "maximumProbingPeriod";
        private const string MinimumProbingPeriodTag = "minimumProbingPeriod";

        private const string MaximumTitleLengthTag = "maximumTitleLength";
        private const string MinimumTitleLengthTag = "minimumTitleLength";

        private const string BackUpStationRecorderTag = "backUpStationRecorder";

        private const string MaximumRecordingAgeTag = "maximumRecordingAge";
        private const string CancelIfExistsTag = "cancelIfExists";
        private const string LoggerParameterTag = "loggerParameter";
        private const string StagingFolderTag = "stagingFolder";
        private const string StreamTitleFiltersTag = "streamTitleFilters";
        private const string DatePatternsTag = "datePatterns";

        [ConfigurationProperty(NameTag, IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)this[NameTag]; }
        }

        [ConfigurationProperty(UrlTag, IsRequired = true)]
        public string Url
        {
            get { return (string)this[UrlTag]; }
        }

        [ConfigurationProperty(BackUpStationRecorderTag, IsRequired = false)]
        public string BackUpStationRecorder
        {
            get { return (string)this[BackUpStationRecorderTag]; }
        }

        [ConfigurationProperty(UserAgentTag, IsRequired = true)]
        public string UserAgent
        {
            get { return (string)this[UserAgentTag]; }
        }
                
        [ConfigurationProperty(ArchiveFolderTag, IsRequired = true)]
        public string ArchiveFolder
        {
            get { return (string)this[ArchiveFolderTag]; }
        }

        [ConfigurationProperty(MaximumProbingPeriodTag, IsRequired = true)]
        public TimeSpan MaximumProbingPeriod
        {
            get { return (TimeSpan)this[MaximumProbingPeriodTag]; }
        }

        [ConfigurationProperty(MinimumProbingPeriodTag, IsRequired = true)]
        public TimeSpan MinimumProbingPeriod
        {
            get { return (TimeSpan)this[MinimumProbingPeriodTag]; }
        }

        [ConfigurationProperty(MaximumTitleLengthTag, IsRequired = true)]
        public TimeSpan MaximumTitleLength
        {
            get { return (TimeSpan)this[MaximumTitleLengthTag]; }
        }

        [ConfigurationProperty(MinimumTitleLengthTag, IsRequired = true)]
        public TimeSpan MinimumTitleLength
        {
            get { return (TimeSpan)this[MinimumTitleLengthTag]; }
        }

        [ConfigurationProperty(MaximumRecordingAgeTag, IsRequired = true)]
        public TimeSpan MaximumRecordingAge
        {
            get { return (TimeSpan)this[MaximumRecordingAgeTag]; }
        }

        [ConfigurationProperty(CancelIfExistsTag, IsRequired = true)]
        public bool CancelIfExists
        {
            get { return Convert.ToBoolean(this[CancelIfExistsTag]); }
        }

        [ConfigurationProperty(LoggerParameterTag, IsRequired = true)]
        public string LoggerParameter
        {
            get { return (string)this[LoggerParameterTag]; }
        }

        [ConfigurationProperty(StagingFolderTag, IsRequired = true)]
        public string StagingFolder
        {
            get { return (string)this[StagingFolderTag]; }
        }

        [ConfigurationProperty(StreamTitleFiltersTag, IsRequired = true)]
        public StreamTitleFilterElementCollection StreamTitleFilters
        {
            get { return (StreamTitleFilterElementCollection)this[StreamTitleFiltersTag]; }
        }
        [ConfigurationProperty(DatePatternsTag, IsRequired = false)]
        public DatePatternElementCollection DatePatterns
        {
            get { return (DatePatternElementCollection) this[DatePatternsTag]; }
        }

        public override string ToString()
        {
            return ObjectDumper.Format(this);
        }

        public override bool IsReadOnly()
        {
            return false;
        }
    }
}
